/**
 * ReportGear(2011)
 */
package com.reportgear.report.model.calculator;

import java.util.Iterator;

import com.reportgear.core.data.SalaryHelper;
import com.reportgear.core.data.model.SalaryDataObject;
import com.reportgear.report.context.ReportContext;
import com.reportgear.report.model.ReportModel;
import com.reportgear.report.model.cell.Cell;
import com.reportgear.report.model.cell.value.salary.SalaryPayObject;

/**
 * 
 * 发放表计算信息计算
 * 
 * @version 1.0 2011-6-5
 * @author <a herf="lexloo@gmail.com">lexloo</a>
 * @since Report 1.0
 */
public class PayInfoCalculator extends AbstractCalculator {
	public PayInfoCalculator() {

	}

	@Override
	public ReportModel calculate(ReportModel model, CalcParameter parameter) {
		if (logger.isDebugEnabled()) {
			logger.debug("计算模型：工资对象计算");
		}

		ReportModel calcModel = model;

		this.doCalculate(calcModel);

		return calcModel;
	}

	/**
	 * 计算
	 * 
	 * @param model
	 *            模型
	 */
	private void doCalculate(ReportModel model) {
		SalaryDataObject sdo = SalaryHelper.INSTANCE.getPayBase(ReportContext.INSTANCE.getPaymentId());

		Iterator<Cell> iter = model.getCellsIteratorByCellElementClass(SalaryPayObject.class);
		for (Iterator<Cell> i = iter; i.hasNext();) {
			Cell cell = i.next();
			String field = ((SalaryPayObject) cell.getValue()).getField();
			cell.setValue(sdo.getString(field));
		}
	}
}
